*Paper: Fiscal Rules, Corruption and Electoral Accountability - Replication Files

*NB: the version of rdrobust is: "version 9.1.0  2022-10-28" 
*which rdrobust

clear all
cap log close 
set more off


**Global files
global folder "/Users/tommasogiommoni/Dropbox/Determinants of corruption/Stability pact and corruption/Replication files JOP"


********************************************************************************
****----						Dataset open 					    	----**** 
********************************************************************************

use "$folder/Data/dataset_feb2024.dta", clear

**-- Global

global controls7 proportion_female_Elected_lag av_education_Elected_lag av_age_Elected_lag  victory_margin_lag term_limit_lag 
global covs_bandwidth anno_FE* 
global FE_regres anno id_provincia
global control_set $controls7 education_mayor_lag age_mayor_lag gender_mayor_lag
global cluster_regr codcom 

**-- Panel dataset

xtset codcom anno
fvset base 2012 anno

**-- Additional cleaning

keep  if population_anagrafe<10000

********************************************************************************
****----						Analysis 					    		----**** 
********************************************************************************

****---- All regions ----****

**-- Optimal bandwidth computation

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if population_anagrafe<10000 & anno>2012 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band1=e(h_l)
qui rdrobust `var' P if population_anagrafe<10000 & anno<2013 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs()
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P)<B`var'
gen	B`var'2=(`band1'+`band2')/1.33
gen S`var'2 = abs(P)<B`var'2
gen	B`var'3=(`band1'+`band2')/1.6
gen S`var'3 = abs(P)<B`var'3

}

**-- Analysis

  reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_1
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_2
  reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC2==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_3
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log2==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_4
  reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC3==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_5
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log3==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab1_6

****---- FCRs ----****

**-- Optimal bandwidth computation

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if population_anagrafe<10000 & anno>2012 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band1=e(h_l)
qui rdrobust `var' P if population_anagrafe<10000 & anno<2013 & FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P)<B`var'
gen	B`var'2=(`band1'+`band2')/1.33
gen S`var'2 = abs(P)<B`var'2
gen	B`var'3=(`band1'+`band2')/1.6
gen S`var'3 = abs(P)<B`var'3

}

**-- Analysis

 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_1
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_2
 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_3
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log2==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_4
 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_5
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log3==1 &  FURs==0 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab2_6

****---- FURs ----****

**-- Optimal bandwidth computation

  capture drop  Scorruption_PC*  Scorruption_exp_log* Bcorruption_PC*  Bcorruption_exp_log*
  capture drop band* sample* 
foreach var in corruption_PC  corruption_exp_log{
qui rdrobust `var' P if population_anagrafe<10000 & anno>2012 & FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band1=e(h_l)
qui rdrobust `var' P if population_anagrafe<10000 & anno<2013 & FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA") , covs() 
local band2=e(h_l)
local band=(`band1'+`band2')/2
display "`band'"
gen	B`var'=(`band1'+`band2')/2
gen S`var' = abs(P)<B`var'
gen	B`var'2=(`band1'+`band2')/1.33
gen S`var'2 = abs(P)<B`var'2
gen	B`var'3=(`band1'+`band2')/1.6
gen S`var'3 = abs(P)<B`var'3

}

**-- Analysis

 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_1
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_2
 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC2==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_3
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log2==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_4
 reghdfe corruption_PC_sd S P T ST PT PS PST $control_set if Scorruption_PC3==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_5
 reghdfe corruption_exp_log_sd S P T ST PT PS PST $control_set if Scorruption_exp_log3==1 &  FURs==1 & (special_region==0 | regione=="SICILIA" | regione=="SARDEGNA"), cluster($cluster_regr) absorb($FE_regres)
est store tab3_6

****---- Table ----****
 
esttab tab1_1 tab1_2 tab2_1 tab2_2 tab3_1 tab3_2 using "$folder/Tables/TableA14_panelA.tex", compress keep(ST) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
esttab tab1_5 tab1_6 tab2_5 tab2_6 tab3_5 tab3_6 using "$folder/Tables/TableA14_panelB.tex", compress keep(ST) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
esttab tab1_3 tab1_4 tab2_3 tab2_4 tab3_3 tab3_4 using "$folder/Tables/TableA14_panelC.tex", compress keep(ST) se r2 staraux collabels(, none) ml(,none) cells(b(star fmt (%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) replace
